#ifndef _IMAGE_H_
#define _IMAGE_H_

class Disk;

#include <string>
#include "vec.hpp"

class Image
{
public:
	Image();
	~Image();
	bool Open(const std::string & name);
	bool Open(const char *name)
	{
		return Open(std::string(name));
	};
	bool Opened();
	void Close();

	//void GridDraw(const wchar_t *grid, int gcols, int grows);
	void RowDraw(const wchar_t *row, int n, const Matf &transform);
	void Draw(int tile, const Matf &transform);

	unsigned Cols() 
	{
		return cols;
	};

	int Tile(int col, int row)
	{
		return (row * cols) + col;
	};

	int TileCt()
	{
		return rows * cols;
	};

	int TileAtPoint(float x, float y);

	int TileRow(int tile)
	{
		return tile / cols;
	};

	int TileCol(int tile)
	{
		return tile % cols;
	};

	float TileWidth()
	{
		return tilew;
	}

	float TileHeight()
	{
		return tileh;
	}
	
	float Width()
	{
		return tilew * cols;
	}

	float Height()
	{
		return tileh * rows;
	}

	void Clamp(int & col, int & row);

private:
	unsigned int tex;
	//unsigned int *texes;
	unsigned short cols, rows;
	float invcols, invrows;
	float tilew, tileh;
	
	void InfoOpen(const char *filename);
	
};

#include "assets.hpp"
extern Assets<Image> AllImgs;

#endif
